package com.gitee.dufafei.spark.conf

import java.util.Properties

class Resource(mode: String, separator: String = "_") {

  def getProperties(name: String): Properties = {
    val props = new Properties()
    if(name.endsWith(".properties")) {
      val inputStream = getClass.getClassLoader.getResourceAsStream(mode + separator + name)
      props.load(inputStream)
      props
    } else {
      val inputStream = getClass.getClassLoader.getResourceAsStream(mode + separator + name + ".properties")
      props.load(inputStream)
      props
    }
  }
}

object Resource {

  def apply(mode: String, separator: String): Resource = new Resource(mode, separator)

  def apply(mode: String): Resource = new Resource(mode)
}
